<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>日报文章</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travelContent.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/collectAndCancel.js"></script>
    <script>
        $(function () {
            var userStr = sessionStorage.getItem('user');
            var params = getParams();
            var dailyId = params.id;
            if (dailyId){
                // console.log(params.id);
                var like;
                var likeNum;
                $.get(baseUrl+'/dailies/selectById/'+dailyId,function (data) {
                    // console.log(data);
                    $('.travels').renderValues(data);
                    likeNum = data.likeNum;
                    like = data.like+'';
                    if (like=='true'){
                        $('#likeBtn').removeClass('fa-thumbs-o-up').addClass('fa-thumbs-up').attr('style',"color: #00bbd3");
                    }
                })//增加浏览量
                $.get(baseUrl+'/dailies/updateBrowseNumById/'+dailyId)

                //点赞和取消
                $("#likeBtn").click(function () {
                    if (!userStr) {
                        $(document).dialog({
                            type: 'confirm',
                            closeBtnShow: true,
                            content: '你还没登录,立刻登录?',
                            onClickConfirmBtn: function () {
                                window.location.href = '/login.html';
                            },
                            onClickCancelBtn: function () {
                            }
                        });
                        return;
                    }

                    if (like=='true'){
                        like = 'false';
                        $('#likeBtn').removeClass('fa-thumbs-up').addClass('fa-thumbs-o-up').attr('style',"color: black");
                        $('#likeBtn').html(--likeNum);
                        $.ajax({
                            type: "delete",
                            url: baseUrl+'/users/cancelLike/'+dailyId+'/'+3,//type: 1.游记;2.大攻略;3.日报;4.攻略文章
                            success: function () {
                                $(document).dialog({
                                    type: 'notice',
                                    infoText: '已取消',
                                    autoClose: 1000,
                                    position: 'center'  // center: 居中; bottom: 底部
                                });
                            }
                        })
                    }else {
                        like = 'true';
                        $('#likeBtn').removeClass('fa-thumbs-o-up').addClass('fa-thumbs-up').attr('style',"color: #00bbd3");
                        $('#likeBtn').html(++likeNum);
                        $.ajax({
                            type: "post",
                            url: baseUrl+'/users/like/'+dailyId+'/'+3,//type: 1.游记;2.大攻略;3.日报;4.攻略文章

                            success: function () {
                                $(document).dialog({
                                    type: 'notice',
                                    infoText: '谢谢点赞!',
                                    autoClose: 1000,
                                    position: 'center'  // center: 居中; bottom: 底部
                                });
                            }
                        })
                    }
                });
            };

            //点击评论图标按钮跳转到评论页面
            $("#commentBtn").click(function(){
                if (!userStr) {
                    $(document).dialog({
                        type: 'confirm',
                        closeBtnShow: true,
                        content: '你还没登录,立刻登录?',
                        onClickConfirmBtn: function () {
                            window.location.href = '/login.html';
                        },
                        onClickCancelBtn: function () {
                        }
                    });
                    return;
                }
                window.location.href="/mine/dailyComment.html?id="+params.id;
            });

            //查询当前用户是否对该日报有收藏
            $.get(baseUrl + "/users/dailyCollection/" + params.id,function (data) {
                changeClass(data);
            })

            //点击收藏改变样子,发送请求
            $("#collectBtn").click(function () {
                //检查登录
                if (!userStr) {
                    $(document).dialog({
                        type: 'confirm',
                        closeBtnShow: true,
                        content: '你还没登录,立刻登录?',
                        onClickConfirmBtn: function () {
                            window.location.href = '/login.html';
                        },
                        onClickCancelBtn: function () {
                        }
                    });
                    return;
                }

                //点击收藏和取消收藏
                var url = baseUrl + '/users/changeDailyCollection/' + params.id;
                collectAndCancel(url);
            });
        });


    </script>
</head>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
        </div>
    </div>
</div>

<div class="travels">
    <img  class="cover" render-src="coverUrl">
    <div class="container">
        <h6 class="title" render-html="title" >飞到羊城，只为一场最地道的早茶之旅</h6>
        <small>
            <span render-html="releaseTime" >2018-07-11</span>
            浏览 <span render-html="browseNum" > 0</span>
            回复 <span> 0</span>
        </small>
    </div>
    ,
    <div class="container">

        <div class="content" render-html="dailyContent.content" >
        </div>
    </div>

    <hr>

    <div class="container d-flex">
        <div class="p-2  flex-fill">
            <i class="fa fa-thumbs-o-up" id="likeBtn" render-html="likeNum"> </i>
        </div>
        <div class="p-2  flex-fill"><i class="fa  fa-commenting-o"  id="commentBtn" render-html="commentNum"> </i>
        </div>
        <div class="p-2  flex-fill"><i class="fa fa-star-o" id="collectBtn" data-collection=""> </i>
        </div>
    </div>
</div>



</body>

</html>